package com.csun.cmny.provider.controller;


import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.dto.OmcRemoteCareLogDto;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.OmcServiceOrderCarelogService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/remoteCare")
public class OmcRemoteCareLogController extends BaseController {

    @Resource
    private CmnyMessageSource cmnyMessageSource;
    @Resource
    private OmcServiceOrderCarelogService omcServiceOrderCarelogService;

    /**
     * 根据订单id查询工作日志
     *
     * @param orderId
     *
     * @return  the wrapper.
     */
    @PostMapping(value = "/listWorkLog/{orderId}")
    public Wrapper listWorkLog(@PathVariable Long orderId) {

        PageInfo pageInfo=omcServiceOrderCarelogService.listPage(orderId);

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null),pageInfo);
    }

    /**
     * 保存工作日志
     *
     * @param omcRemoteCareLogDto 工作日志
     *
     * @return  the wrapper
     */
    @PostMapping(value = "/save")
    public Wrapper save(@Validated @RequestBody OmcRemoteCareLogDto omcRemoteCareLogDto) {

        Integer result=omcServiceOrderCarelogService.saveRemoteCareLog(omcRemoteCareLogDto);

        if (result < 1) {
            return WrapMapper.wrap(Wrapper.ERROR_CODE, cmnyMessageSource
                    .getMessage("operation.failed", null));
        }

        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, cmnyMessageSource
                .getMessage("operation.success", null),result);
    }
}
